﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace FWMS
{
    public partial class Form_chukumingxi_details : Form
    {
        public Form_chukumingxi_details()
        {
            InitializeComponent();
        }

        private void Form_chukumingxi_details_Load(object sender, EventArgs e)
        {

        }

        /**
         * 自窗口调用
         * 参数zhongliang_shengyu 剩余重量
         * 
         * */
        public void selfShow(int tabIndex , Object bean,Object pinming,Object zhongliang_total, Object zhongliang_shengyu, DateTimePicker dateStartDate, DateTimePicker dateEndDate)
        {
            if (tabIndex == 0)
            {
                this.label4.Text = "  当前品名：" + pinming.ToString();
                //集计开始日期和结束日期取得并显示在页面中
                this.label1.Text = dateStartDate.Value.ToString("yyyy年MM月dd日") + "-" + dateEndDate.Value.ToString("yyyy年MM月dd日");
                writeData(tabIndex, bean, pinming, zhongliang_total, zhongliang_shengyu, dateStartDate, dateEndDate);
                this.ShowDialog();
            }
            if (tabIndex == 1)
            {
                this.label4.Text = "  当前品名：" + pinming.ToString();
                //集计开始日期和结束日期取得并显示在页面中
                this.label1.Text = dateStartDate.Value.ToString("yyyy年MM月dd日") + "-" + dateEndDate.Value.ToString("yyyy年MM月dd日");
                writeData(tabIndex, bean, pinming, zhongliang_total, zhongliang_shengyu, dateStartDate, dateEndDate);
                this.ShowDialog();
            }
            else if (tabIndex == 2)
            {
                this.label4.Text = "  当前品名：" + pinming.ToString();
                //集计开始日期和结束日期取得并显示在页面中
                this.label1.Text = dateStartDate.Value.ToString("yyyy年MM月dd日") + "-" + dateEndDate.Value.ToString("yyyy年MM月dd日");
                writeData(tabIndex, bean, pinming, zhongliang_total, zhongliang_shengyu, dateStartDate, dateEndDate);
                this.ShowDialog();
            }
            else if (tabIndex == 3)
            {
                this.label4.Text = "  当前品名：" + pinming.ToString();
                //集计开始日期和结束日期取得并显示在页面中
                this.label1.Text = dateStartDate.Value.ToString("yyyy年MM月dd日") + "-" + dateEndDate.Value.ToString("yyyy年MM月dd日");
                writeData(tabIndex, bean, pinming, zhongliang_total, zhongliang_shengyu, dateStartDate, dateEndDate);
                this.ShowDialog();

            }
           
        }

        /**
         * 根据日期像页面输出数据
         * 参数：集计开始日期和结束日期
         * 
         * */
        private void writeData(int tabIndex,Object bean, Object pinming,Object zhongliang_total,Object zhongliang_shengyu, DateTimePicker dateStartDate, DateTimePicker dateEndDate)
        {
            //MessageBox.Show(dateStartDate.Value.CompareTo(dateEndDate.Value).ToString());


            if (tabIndex == 0)
            {
                bean = (Bean.Chukuguanli_yuancailiaoBean)bean;
            }
            else if (tabIndex == 1)
            { 
                bean = (Bean.Chukuguanli_tiaoweiliaoBean)bean;
            }
            else if (tabIndex == 2)
            {
                bean = (Bean.Chukuguanli_fuliaoBean)bean;
            }
            else if (tabIndex == 3)
            {
                bean = (Bean.Chukuguanli_chanpinBean)bean;
            }
            int period = (dateEndDate.Value - dateStartDate.Value).Days + 1;

            if (period > 32)
            {
                MessageBox.Show("集计时间范围超出，请重新选择集计时间段！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            Label lbl_day1 = new Label();
            switch (dateStartDate.Value.DayOfWeek.ToString())
            {
                case "Sunday":

                    //  this.Controls.Add(lbl_day1);
                    //   lbl_day1.Size = new System.Drawing.Size(79, 73);
                    lbl_day1.Location = new System.Drawing.Point(10, 37);
                    lbl_day1.AutoSize = true;
                    lbl_day1.Text = dateStartDate.Value.Month + "月" + dateStartDate.Value.Day.ToString() + "日";
                    break;
                case "Monday":
                    // Label lbl_day1 = new Label();
                    // this.Controls.Add(lbl_day1);
                    // lbl_day1.Size = new System.Drawing.Size(120, 73);
                    lbl_day1.Location = new System.Drawing.Point(95, 37);
                    lbl_day1.AutoSize = true;
                    lbl_day1.Text = dateStartDate.Value.Month + "月" + dateStartDate.Value.Day.ToString() + "日";
                    //     drawDay(bean,period, lbl_day1, dateStartDate, dateEndDate);
                    break;
                case "Tuesday":
                    lbl_day1.Location = new System.Drawing.Point(180, 37);
                    lbl_day1.AutoSize = true;
                    lbl_day1.Text = dateStartDate.Value.Month + "月" + dateStartDate.Value.Day.ToString() + "日";
                    // drawDay(bean,period, lbl_day1, dateStartDate, dateEndDate);
                    //lbl_day1.Location = new System.Drawing.Point(177, 55);
                    break;
                case "Wednesday":
                    lbl_day1.Location = new System.Drawing.Point(265, 37);
                    lbl_day1.AutoSize = true;
                    lbl_day1.Text = dateStartDate.Value.Month + "月" + dateStartDate.Value.Day.ToString() + "日";
                    //drawDay(bean,period, lbl_day1, dateStartDate, dateEndDate);
                    //  lbl_day1.Location = new System.Drawing.Point(262, 55);
                    break;
                case "Thursday":
                    lbl_day1.Location = new System.Drawing.Point(350, 37);
                    lbl_day1.AutoSize = true;
                    lbl_day1.Text = dateStartDate.Value.Month + "月" + dateStartDate.Value.Day.ToString() + "日";
                    //   drawDay(bean,period, lbl_day1, dateStartDate, dateEndDate);
                    //// lbl_day1.Location = new System.Drawing.Point(347, 55);
                    break;
                case "Friday":
                    lbl_day1.Location = new System.Drawing.Point(435, 37);
                    lbl_day1.AutoSize = true;
                    lbl_day1.Text = dateStartDate.Value.Month + "月" + dateStartDate.Value.Day.ToString() + "日";
                    //   drawDay(bean,period, lbl_day1, dateStartDate, dateEndDate);
                    //lbl_day1.Location = new System.Drawing.Point(432, 55);
                    break;
                case "Saturday":
                    lbl_day1.Location = new System.Drawing.Point(520, 37);
                    lbl_day1.AutoSize = true;
                    lbl_day1.Text = dateStartDate.Value.Month + "月" + dateStartDate.Value.Day.ToString() + "日";
                    // drawDay(bean,period, lbl_day1, dateStartDate, dateEndDate);
                    break;
                default:
                    break;

            }
            drawDay(tabIndex, zhongliang_total, zhongliang_shengyu, bean, period, lbl_day1, dateStartDate, dateEndDate);  
           

           
        }

        /**
         * 选择阶段的日期输出页面
         * 
         * 参数：期间，设定LABEL，开始时间，结束时间
         * 
         * */
        private void drawDay(int tabIndex , Object zhongliang_total,Object zhongliang_shengyu, Object databean ,int period,Label lbl_day1, DateTimePicker dateStartDate, DateTimePicker dateEndDate)
        {

            if (tabIndex == 0)
            {
                Bean.Chukuguanli_yuancailiaoBean bean = (Bean.Chukuguanli_yuancailiaoBean)databean;
                 DateTime tempDateStart = new DateTime();

                 string startDay = dateStartDate.Value.ToString("yyyy-MM-dd");

                 tempDateStart = DateTime.Parse(startDay);

                 //设定当前坐标
                 int col = lbl_day1.Location.X;
                 int line = 55;
                 for (int i = 0; i < period; i++)
                 {
                     //日期LABEL
                     Label label = new Label();
                     label.Location = new System.Drawing.Point(col, line);
                     label.Text = tempDateStart.Month + "月" + tempDateStart.Day.ToString() + "日";
                     label.AutoSize = true;
                     this.Controls.Add(label);

                     //重量LABEL
                     Label label_zhongliang = new Label();
                     label_zhongliang.Location = new System.Drawing.Point(label.Location.X, label.Location.Y + label.Height + 5);
                     //label_zhongliang.Text = tempDateStart.Month + "月" + tempDateStart.Day.ToString() + "日";
                     label_zhongliang.AutoSize = true;

                     //集计后重量Label
                     Label label_jijiZhongliang = new Label();
                     label_jijiZhongliang.Location = new System.Drawing.Point(label_zhongliang.Location.X, label_zhongliang.Location.Y + label.Height + 5);
                     //label_zhongliang.Text = tempDateStart.Month + "月" + tempDateStart.Day.ToString() + "日";
                     label_jijiZhongliang.AutoSize = true;

                     for (int j = 0; j < bean.Resultrow; j++)
                     {
                         if (tempDateStart.ToString("yyyyMMdd").Equals(bean.Selectresult[j, 2].ToString()))
                         {
                             //重量赋值
                             label_zhongliang.Text = bean.Selectresult[j, 1].ToString();
                             label.ForeColor = System.Drawing.Color.Red;
                             label_zhongliang.ForeColor = System.Drawing.Color.Purple;

                         }

                     }



                     this.Controls.Add(label_zhongliang);
                     this.Controls.Add(label_jijiZhongliang);

                     tempDateStart = tempDateStart.AddDays(1);
                     //  MessageBox.Show(label.Location.X.ToString());
                     if ("Sunday".Equals(tempDateStart.DayOfWeek.ToString()))
                     {
                         //如果是星期日则换行显示
                         col = 10;
                         line = label.Location.Y + label.Height + 50;
                     }
                     else
                     {
                         col = col + 85;
                     }
                 }

            }
            else if (tabIndex == 1)
            {

               Bean.Chukuguanli_tiaoweiliaoBean bean = (Bean.Chukuguanli_tiaoweiliaoBean)databean;
                 DateTime tempDateStart = new DateTime();

                 string startDay = dateStartDate.Value.ToString("yyyy-MM-dd");

                 tempDateStart = DateTime.Parse(startDay);

                 //设定当前坐标
                 int col = lbl_day1.Location.X;
                 int line = 55;
                 for (int i = 0; i < period; i++)
                 {
                     //日期LABEL
                     Label label = new Label();
                     label.Location = new System.Drawing.Point(col, line);
                     label.Text = tempDateStart.Month + "月" + tempDateStart.Day.ToString() + "日";
                     label.AutoSize = true;
                     this.Controls.Add(label);

                     //重量LABEL
                     Label label_zhongliang = new Label();
                     label_zhongliang.Location = new System.Drawing.Point(label.Location.X, label.Location.Y + label.Height + 5);
                     //label_zhongliang.Text = tempDateStart.Month + "月" + tempDateStart.Day.ToString() + "日";
                     label_zhongliang.AutoSize = true;

                     //集计后重量Label
                     Label label_jijiZhongliang = new Label();
                     label_jijiZhongliang.Location = new System.Drawing.Point(label_zhongliang.Location.X, label_zhongliang.Location.Y + label.Height + 5);
                     //label_zhongliang.Text = tempDateStart.Month + "月" + tempDateStart.Day.ToString() + "日";
                     label_jijiZhongliang.AutoSize = true;

                     for (int j = 0; j < bean.Resultrow; j++)
                     {
                         if (tempDateStart.ToString("yyyyMMdd").Equals(bean.Selectresult[j, 2].ToString()))
                         {
                             //重量赋值
                             label_zhongliang.Text = bean.Selectresult[j, 1].ToString();
                             label.ForeColor = System.Drawing.Color.Red;
                             label_zhongliang.ForeColor = System.Drawing.Color.Purple;

                         }

                     }



                     this.Controls.Add(label_zhongliang);
                     this.Controls.Add(label_jijiZhongliang);

                     tempDateStart = tempDateStart.AddDays(1);
                     //  MessageBox.Show(label.Location.X.ToString());
                     if ("Sunday".Equals(tempDateStart.DayOfWeek.ToString()))
                     {
                         //如果是星期日则换行显示
                         col = 10;
                         line = label.Location.Y + label.Height + 50;
                     }
                     else
                     {
                         col = col + 85;
                     }
                 
                }

            }
            else if (tabIndex == 2)
            {
                Bean.Chukuguanli_fuliaoBean bean = (Bean.Chukuguanli_fuliaoBean)databean;
                DateTime tempDateStart = new DateTime();

                string startDay = dateStartDate.Value.ToString("yyyy-MM-dd");

                tempDateStart = DateTime.Parse(startDay);

                //设定当前坐标
                int col = lbl_day1.Location.X;
                int line = 55;
                for (int i = 0; i < period; i++)
                {
                    //日期LABEL
                    Label label = new Label();
                    label.Location = new System.Drawing.Point(col, line);
                    label.Text = tempDateStart.Month + "月" + tempDateStart.Day.ToString() + "日";
                    label.AutoSize = true;
                    this.Controls.Add(label);

                    //重量LABEL
                    Label label_zhongliang = new Label();
                    label_zhongliang.Location = new System.Drawing.Point(label.Location.X, label.Location.Y + label.Height + 5);
                    //label_zhongliang.Text = tempDateStart.Month + "月" + tempDateStart.Day.ToString() + "日";
                    label_zhongliang.AutoSize = true;

                    //集计后重量Label
                    Label label_jijiZhongliang = new Label();
                    label_jijiZhongliang.Location = new System.Drawing.Point(label_zhongliang.Location.X, label_zhongliang.Location.Y + label.Height + 5);
                    //label_zhongliang.Text = tempDateStart.Month + "月" + tempDateStart.Day.ToString() + "日";
                    label_jijiZhongliang.AutoSize = true;

                    for (int j = 0; j < bean.Resultrow; j++)
                    {
                        if (tempDateStart.ToString("yyyyMMdd").Equals(bean.Selectresult[j, 2].ToString()))
                        {
                            //重量赋值
                            label_zhongliang.Text = bean.Selectresult[j, 1].ToString();
                            label.ForeColor = System.Drawing.Color.Red;
                            label_zhongliang.ForeColor = System.Drawing.Color.Purple;

                        }

                    }



                    this.Controls.Add(label_zhongliang);
                    this.Controls.Add(label_jijiZhongliang);

                    tempDateStart = tempDateStart.AddDays(1);
                    //  MessageBox.Show(label.Location.X.ToString());
                    if ("Sunday".Equals(tempDateStart.DayOfWeek.ToString()))
                    {
                        //如果是星期日则换行显示
                        col = 10;
                        line = label.Location.Y + label.Height + 50;
                    }
                    else
                    {
                        col = col + 85;
                    }

                }
            }
            else if (tabIndex == 3)
            {
                Bean.Chukuguanli_chanpinBean bean = (Bean.Chukuguanli_chanpinBean)databean;
                DateTime tempDateStart = new DateTime();

                string startDay = dateStartDate.Value.ToString("yyyy-MM-dd");

                tempDateStart = DateTime.Parse(startDay);

                //设定当前坐标
                int col = lbl_day1.Location.X;
                int line = 55;
                for (int i = 0; i < period; i++)
                {
                    //日期LABEL
                    Label label = new Label();
                    label.Location = new System.Drawing.Point(col, line);
                    label.Text = tempDateStart.Month + "月" + tempDateStart.Day.ToString() + "日";
                    label.AutoSize = true;
                    this.Controls.Add(label);

                    //重量LABEL
                    Label label_zhongliang = new Label();
                    label_zhongliang.Location = new System.Drawing.Point(label.Location.X, label.Location.Y + label.Height + 5);
                    //label_zhongliang.Text = tempDateStart.Month + "月" + tempDateStart.Day.ToString() + "日";
                    label_zhongliang.AutoSize = true;

                    //集计后重量Label
                    Label label_jijiZhongliang = new Label();
                    label_jijiZhongliang.Location = new System.Drawing.Point(label_zhongliang.Location.X, label_zhongliang.Location.Y + label.Height + 5);
                    //label_zhongliang.Text = tempDateStart.Month + "月" + tempDateStart.Day.ToString() + "日";
                    label_jijiZhongliang.AutoSize = true;

                    for (int j = 0; j < bean.Resultrow; j++)
                    {
                        if (tempDateStart.ToString("yyyyMMdd").Equals(bean.Selectresult[j, 2].ToString()))
                        {
                            //重量赋值
                            label_zhongliang.Text = bean.Selectresult[j, 1].ToString();
                            label.ForeColor = System.Drawing.Color.Red;
                            label_zhongliang.ForeColor = System.Drawing.Color.Purple;

                        }

                    }



                    this.Controls.Add(label_zhongliang);
                    this.Controls.Add(label_jijiZhongliang);

                    tempDateStart = tempDateStart.AddDays(1);
                    //  MessageBox.Show(label.Location.X.ToString());
                    if ("Sunday".Equals(tempDateStart.DayOfWeek.ToString()))
                    {
                        //如果是星期日则换行显示
                        col = 10;
                        line = label.Location.Y + label.Height + 50;
                    }
                    else
                    {
                        col = col + 85;
                    }

                }
            }

        }



    }
}
